package com.tanhua.dubbo.api.impl.mongo;

import com.tanhua.domain.mongo.Sound;
import com.tanhua.dubbo.api.mongo.PeachblossomApi;
import org.apache.dubbo.config.annotation.Service;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Service
public class PeachblossomApiImpl implements PeachblossomApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 保存语音信息
     * @param
     * @param userId
     */
    @Override
    public void saveVocie(String soundUrl, Long userId) {

        Sound voice = new Sound();
        voice.setId(ObjectId.get());
        voice.setUserId(userId);
        voice.setSoundUrl(soundUrl);
        voice.setCreated(System.currentTimeMillis());

        mongoTemplate.save(voice);

    }

    @Override
    public List<Sound> findAllSound() {
        List<Sound> soundList = mongoTemplate.find(new Query(), Sound.class);
        return soundList;
    }
}
